package ace.module.upms.core.impl.api.impl;

import ace.cmp.core.model.R;
import ace.module.common.api.annotation.ApiLocalPriority;
import ace.module.common.api.model.input.AppIdListInput;
import ace.module.common.core.impl.api.impl.SdkApiImpl;
import ace.module.upms.api.UpmsRoleApi;
import ace.module.upms.api.model.dto.UpmsRoleDto;
import ace.module.upms.api.model.input.UpmsRoleBindAccountInput;
import ace.module.upms.core.impl.dao.entity.UpmsRole;
import ace.module.upms.core.impl.manager.UpmsRoleManager;
import ace.module.upms.core.impl.service.UpmsRoleService;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;


/**
 * 角色对象 api implements.
 *
 * @author Caspar
 *
 */
@ApiLocalPriority
@AllArgsConstructor
@Component
public class UpmsRoleApiImpl
    extends SdkApiImpl<UpmsRole, Long, UpmsRoleDto, UpmsRoleManager>
    implements UpmsRoleApi {

  private final UpmsRoleService upmsRoleService;

  @Override
  public R<Map<Long, List<UpmsRoleDto>>> getAccountIdAndRoleMapByUpmsAppIdAndIamAccountIdIn(
      Long upmsAppId,
      List<Long> iamAccountIds) {
    Map<Long, List<UpmsRoleDto>> result = this.upmsRoleService.getAccountIdAndRoleMapByUpmsAppIdAndIamAccountIdIn(
        upmsAppId,
        iamAccountIds
    );

    return R.ok(result);
  }

  @Override
  public R<List<UpmsRoleDto>> getByUpmsApIdAndIamAccountId(
      Long upmsAppId,
      Long iamAccountId) {
    List<UpmsRoleDto> result = this.upmsRoleService.getByUpmsApIdAndIamAccountId(
        upmsAppId,
        iamAccountId
    );

    return R.ok(result);
  }

  @Override
  public R<Void> saveRoleAccountRelation(AppIdListInput<UpmsRoleBindAccountInput> inputs) {
    this.upmsRoleService.saveRoleAccountRelation(inputs);
    return R.ok();
  }
}
